package com.htd.base.common.config;

import com.htd.base.common.filter.DataSourceContextFilter;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan(basePackages = {"com.htd.base"})
@EnableConfigurationProperties(LsCoreProperties.class)//你需要注入的Bean所在的包,是个数组可以多个
public class LsCoreConfig {

    private final LsCoreProperties properties;

    public LsCoreConfig(LsCoreProperties properties) {
        this.properties = properties;
    }

    @Bean
    public String languageDataBaseKey(){
        return properties.getBase().language().database().getKey();
    }

    @Bean
    public FilterRegistrationBean<DataSourceContextFilter> dataSourceContextFilter() {
        FilterRegistrationBean<DataSourceContextFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new DataSourceContextFilter());
        registrationBean.addUrlPatterns("/*");
        registrationBean.setOrder(1);
        return registrationBean;
    }
}


